package com.open.capacity.reimburse.controller;

import java.util.Map;

import com.open.capacity.commons.Result;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.reimburse.entity.PbdBudgetAdjust2;
import com.open.capacity.reimburse.service.PbdBudgetAdjust2Service;

import com.open.capacity.commons.PageResult;

import javax.validation.Valid;

/**
 * 费用分配
 *
 * @author
 * @email
 * @date 2021-06-29 10:26:52
 */
@RestController
@RequestMapping("pbdbudgetadjust2s")
@Api(tags = "费用分配")
public class PbdBudgetAdjust2Controller {

    @Autowired
    private PbdBudgetAdjust2Service pbdBudgetAdjust2Service;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('pbd_budget_adjust2:pbdbudgetadjust2:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = pbdBudgetAdjust2Service.pageAll(params);
        return pageResult;
    }


    /**
     * 查询单条记录
     */
    @RequestMapping("/findByDepartmentId")
    @PreAuthorize("hasAnyAuthority('pbd_budget_adjust2:pbdbudgetadjust2:list')")
    public Result findByDepartmentId(String projectId, String departmentId) {
        return Result.succeed(pbdBudgetAdjust2Service.findByDepartmentId(projectId, departmentId));
    }


    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('pbd_budget_adjust2:pbdbudgetadjust2:save')")
    public Result save(Integer year, String projectId, String departmentId, @RequestBody @Valid PbdBudgetAdjust2[] list) {
        pbdBudgetAdjust2Service.saveOrUpdate(year, projectId, departmentId, list);
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('pbd_budget_adjust2:pbdbudgetadjust2:delete')")
    public Result delete(@PathVariable String id) {
        pbdBudgetAdjust2Service.delete(id);
        return Result.succeed("删除成功");
    }

}
